<template>
	<view class="st-comment-block" v-if="comment.total>0">
		<view class="st-comment-bar">
			<view class="title">游客点评<text class="score"><text class="num">{{score}}</text>满意度</text></view>
			<view class="more" @click="productComment"><text class="num">{{comment.total}}</text>条评论<text class="iconfont">&#xe67f;</text></view>
		</view>
		
		<view class="comment">
			<view class="comment-info" v-for="(item,index) in comment.list" :key="item.id">
				<view class="conment-top">
					<view class="user-info">
						<image :src="item.litpic" mode="aspectFill"></image>
						<view>
							<view class="name">{{item.nickname}}</view>
							<view class="date">{{item.addtime}}</view>
						</view>
					</view>
					<view class="score">
						<uni-rate :value="item.level_num" color="#bbb" :size="12" :margin="2" active-color="#f80" readonly />
					</view>
				</view>
				<view class="content">{{item.content}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	/**
	 * 游客点评
	 * @property {String} flag 评论分类
	 * @property {Number} typeid 模型id
	 * @property {Number} productid 产品id
	 * @property {Number} page 页码
	 * @property {Number} pagesize 每页数量
	 */
	export default {
		name: 'st-tourist-comment',
		props: {
			flag: {
				type: String,
				default: ''
			},
			typeid: {
				type: [Number, String],
				default: 0
			},
			productid: {
				type: [Number, String],
				default: 0
			},
			page: {
				type: [Number, String],
				default: 1
			},
			pagesize: {
				type: [Number, String],
				default: 1
			},
			score: {
				type: String,
				default: '100%'
			}
		},
		data() {
			return {
				comment: {
					total: 0
				}
			};
		},
		mounted() {
			switch (this.typeid) {
				case 1:
					if (uni.getStorageSync('cfg_comment_line_lock') == 0) {
						return false
					}
					break;
				case 2:
					if (uni.getStorageSync('cfg_comment_hotel_lock') == 0) {
						return false
					}
					break;
				case 3:
					if (uni.getStorageSync('cfg_comment_car_lock') == 0) {
						return false
					}
					break;
				case 5:
					if (uni.getStorageSync('cfg_comment_spot_lock') == 0) {
						return false
					}
					break;
				case 13:
					if (uni.getStorageSync('cfg_comment_tuan_lock') == 0) {
						return false
					}
					break;
				case 21:
					if (uni.getStorageSync('cfg_comment_malls_lock') == 0) {
						return false
					}
					break;
				case 104:
					if (uni.getStorageSync('cfg_comment_ship_line_lock') == 0) {
						return false
					}
					break;
				case 106:
					if (uni.getStorageSync('cfg_comment_guide_lock') == 0) {
						return false
					}
					break;
				case 114:
					if (uni.getStorageSync('cfg_comment_outdoor_lock') == 0) {
						return false
					}
					break;
				case 118:
					if (uni.getStorageSync('cfg_comment_techan_lock') == 0) {
						return false
					}
					break;
				case 121:
					if (uni.getStorageSync('cfg_comment_food_lock') == 0) {
						return false
					}
					break;
				default:
					if (uni.getStorageSync('cfg_comment_tongyong_lock') == 0) {
						return false
					}
			}
			this.getProductComment();
		},
		methods: {


			// 获取评论
			async getProductComment() {
				let params = {
					method: 'api/v2/comment/list',
					flag: this.flag,
					page: this.page,
					pagesize: this.pagesize,
					product_id: this.productid,
					type_id: this.typeid
				};
				let res = await this.$http(params);
				if (res.status) {
					this.comment = res.data;
				} else {
					uni.showToast({
						title: res.msg,
						icon: "none"
					})
				}
			},
			// 查看点评
			productComment() {
				uni.navigateTo({
					url: '/subPackages/comment/list?typeid=' + this.typeid + "&id=" + this.productid
				})
			}
		}
	}
</script>

<style lang="scss">
	.st-comment-block {
		margin-bottom: $uni-spacing-col-md;
		border-radius: 20rpx;
		background-color: $uni-bg-color;
		.st-comment-bar{
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 24rpx;
			.title{
				display: flex;
				font-size: 34rpx;
				font-weight: bold;
				.score{
					color: #333;
					margin-left: 24rpx;
					font-size: 24rpx;
					font-weight: normal;
					.num{
						color: #2DBB55;
						font-size: 28rpx;
						font-weight: bold;
					}
				}
			}
			.more{
				color: #666;
				font-size: 22rpx;
				font-weight: bold;
				.num{
					font-weight: normal;
				}
				.iconfont{
					display: inline-block;
					vertical-align: middle;
					margin: -4rpx 0 0;
					font-size: 28rpx;
					font-weight: normal;
				}
			}
		}
		
		.conment-top{
			display: flex;
		}

		
		.conment-top {
			align-items: center;
			justify-content: space-between;
		}

		.conment-top {
			margin-bottom: 15rpx;
		}

		.comment {
			padding: 20rpx 25rpx;
		}

		.comment-data {
			font-size: $uni-font-size-mini;
			color: #666;
		}

		.user-info {
			display: flex;
			image {
				width: 60rpx;
				height: 60rpx;
				margin-right: 20rpx;
				border-radius: 50%;
			}

			.name {
				font-size: $uni-font-size-sm;
			}

			.date {
				margin-top: 4rpx;
				font-size: $uni-font-size-mini;
				color: $uni-text-color-grey;
			}
		}

		.score {
			color: #e0e0e0;
			display: flex;
			align-items: center;
		}

		.content {
			line-height: 1.538;
			font-size: 24rpx;
		}
	}
</style>